const express = require("express");
import createApp from "./app.server.js";
import { renderToString } from "@vue/server-renderer";

const server = express();

server.use(express.static("build"));

server.get("/*", async (req, res) => {
  // 创建
  let app = await createApp(req.url);

  // 转化字符串
  let appString = await renderToString(app);
  res.send(
    `
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
          <body>
            <div id="app">${appString}</div>
          </body>
          <script src="/client/client_bundle.js"></script>
    </html>
    `
  );
});

server.listen(3000, () => {
  console.log("Server is running on port 3000");
});
